package deployr.cli;

import deployr.core.*;
import deployr.domain.*;

public class ReadProjectChecksumResponder extends Responder {

	private final Workspace workspace;
	private final Projects projects;

	public ReadProjectChecksumResponder(Workspace workspace, Projects projects) {
		this.workspace = workspace;
		this.projects = projects;
	}

	@Override
	protected Result respondTo(String method, String requestURI, Input input) {

		String projectKey = requestURI.replaceAll(".*/projects/", "").replaceAll("/checksum.*", "");

		IProject project = projects.select(projectKey);
		
		return new Result(200, project.getChecksum());
	}

	@Override
	protected boolean shouldRespond(String method, String requestURI) {
		return "GET".equals(method) && requestURI.matches(".*/projects/.*/checksum.*");
	}

}
